home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / base / net-tool.32- / net-tool / net-tools-1.32-alpha / configure.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1996-01-16  |  3.6 KB  |  162 lines

  1. #! /bin/sh
  2. #
  3. # Configure.sh    Generates interactively a config.h from config.in
  4. #
  5. # net-tools    A collection of programs that form the base set of the
  6. #        NET-3 Networking Distribution for the LINUX operating
  7. #        system.
  8. #
  9. # Usage:    Install.sh [--nobackup] [--test]
  10. #
  11. # Version:    Install.sh 1.65    (1996-01-12)
  12. #
  13. # Authors:    Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  14. #        Johannes Grosen, <grosen@argv.cs.ndsu.nodak.edu>
  15. #        Copyright 1988-1993 MicroWalt Corporation
  16. #
  17. # Modified:
  18. #        {1.65} Bernd eckes Eckenfels <net-tools@lina.inka.de>
  19. #        some layout cleanups, slattach/plipconfig removed.
  20. #        --test for testinstallations added.
  21. #
  22. #        This program is free software; you can redistribute it
  23. #        and/or  modify it under  the terms of  the GNU General
  24. #        Public  License as  published  by  the  Free  Software
  25. #        Foundation;  either  version 2 of the License, or  (at
  26. #        your option) any later version.
  27. #
  28. #
  29. # Make sure we're really running bash.
  30. #
  31. # I would really have preferred to write this script in a language with
  32. # better string handling, but alas, bash is the only scripting language
  33. # that I can be reasonable sure everybody has on their Linux machine.
  34. #
  35.  
  36. CONFIG=config.h
  37.  
  38.  
  39. [ -z "$BASH" ] && { echo "Configure requires bash" 1>&2; exit 1; }
  40.  
  41. # Disable filename globbing once and for all.
  42. # Enable function cacheing.
  43. set -f -h
  44.  
  45. #
  46. # readln reads a line into $ans.
  47. #
  48. #    readln prompt default
  49. #
  50. function readln()
  51. {
  52.   echo -n "$1"
  53.   IFS='@' read ans </dev/tty || exit 1
  54.   [ -z "$ans" ] && ans=$2
  55. }
  56.  
  57. # bool processes a boolean argument
  58. #
  59. #    bool tail
  60. #
  61. function bool()
  62. {
  63.   # Slimier hack to get bash to rescan a line.
  64.   eval "set -- $1"
  65.   ans=""
  66.   while [ "$ans" != "y" -a "$ans" != "n" ]
  67.   do
  68.     readln "$1 ($2) [$3] " "$3"
  69.   done
  70.   if [ "$ans" = "y" ]; then
  71.     echo "#define $2 1" >>${CONFIG}
  72.     else
  73.     echo "#define $2 0" >>${CONFIG}
  74.   fi
  75.   raw_input_line="bool '$1' $2 $ans"
  76.   eval "$2=$ans"
  77. }
  78.  
  79. # int processes an integer argument
  80. #
  81. #    int tail
  82. #
  83. function int()
  84. {
  85.   # Slimier hack to get bash to rescan a line.
  86.   eval "set -- $1"
  87.   ans="x"
  88.   while [ $[$ans+0] != "$ans" ];
  89.   do
  90.     readln "$1 ($2) [$3] " "$3"
  91.   done
  92.   echo "#define $2 ($ans)" >>${CONFIG}
  93.   raw_input_line="int '$1' $2 $ans"
  94.   eval "$2=$ans"
  95. }
  96.  
  97.   #
  98.   # Make sure we start out with a clean slate.
  99.   #
  100.   > config.new
  101.   > ${CONFIG}
  102.  
  103.   stack=''
  104.   branch='t'
  105.  
  106.   while IFS='@' read raw_input_line
  107.   do
  108.     # Slimy hack to get bash to rescan a line.
  109.     read cmd rest <<-END_OF_COMMAND
  110.         $raw_input_line
  111.     END_OF_COMMAND
  112.  
  113.     if [ "$cmd" = "*" ]; then
  114.         if [ "$branch" = "t" ]; then
  115.             echo "$raw_input_line"
  116.             # echo "# $rest" >>$CONFIG
  117.             if [ "$prevcmd" != "*" ]; then
  118.                 echo >>${CONFIG}
  119.                 echo "/* $rest" >>${CONFIG}
  120.             else
  121.                 echo " * $rest" >>${CONFIG}
  122.             fi
  123.             prevcmd="*"
  124.         fi
  125.     else
  126.         [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
  127.         prevcmd=""
  128.         case "$cmd" in
  129.         =)    [ "$branch" = "t" ] && echo "$rest" >>${CONFIG};;
  130.         :)    [ "$branch" = "t" ] && echo "$raw_input_line" ;;
  131.         int)    [ "$branch" = "t" ] && int "$rest" ;;
  132.         bool)    [ "$branch" = "t" ] && bool "$rest" ;;
  133.         exec)    [ "$branch" = "t" ] && ( sh -c "$rest" ) ;;
  134.         if)    stack="$branch $stack"
  135.             if [ "$branch" = "t" ] && eval "$rest"; then
  136.                 branch=t
  137.             else
  138.                 branch=f
  139.             fi ;;
  140.         else)    if [ "$branch" = "t" ]; then
  141.                 branch=f
  142.             else
  143.                 read branch rest <<-END_OF_STACK
  144.                     $stack
  145.                 END_OF_STACK
  146.             fi ;;
  147.         fi)    [ -z "$stack" ] && echo "Error!  Extra fi." 1>&2
  148.             read branch stack <<-END_OF_STACK
  149.                 $stack
  150.             END_OF_STACK
  151.             ;;
  152.         esac
  153.     fi
  154.     echo "$raw_input_line" >>config.new
  155.   done
  156.   [ "$prevcmd" = "*" ] && echo " */" >>${CONFIG}
  157.  
  158.   [ -z "$stack" ] || echo "Error!  Untermiated if." 1>&2
  159.  
  160.   mv config.new config.status
  161.   exit 0
  162.